package com.example.service;

import com.example.mapper.GeekJobMapper;
import com.example.pojo.dto.GeekJobDTO;
import com.example.pojo.entity.JobRecruiter;
import com.example.pojo.entity.Post;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 用于演示 :
 *
 * @author : gao'm
 */
@Service
@Transactional
@SuppressWarnings("all")
public class GeekJobServiceImpl implements GeekJobService{
    @Autowired
    private GeekJobMapper geekJobMapper;

    @Override
    public List<GeekJobDTO> getAll(String searchKey) {
        List<GeekJobDTO> geekJobDTOList = new ArrayList<>();
        List<Post> posts = geekJobMapper.findPost(searchKey);
        for (Post p : posts) {
            int jrId=p.getJrId();
            GeekJobDTO geekJobDTO = new GeekJobDTO();
            geekJobDTO.setPostId(p.getId());
            geekJobDTO.setPosName(p.getPosName());
            geekJobDTO.setWorkPlace(p.getWorkPlace());
            geekJobDTO.setPayFloor(p.getPayFloor());
            geekJobDTO.setPayUpper(p.getPayUpper());
            geekJobDTO.setAgeDemand(p.getAgeDemand());
            geekJobDTO.setSpecialty(p.getSpecialty());
            geekJobDTO.setJobBenefits(p.getJobBenefits());
            geekJobDTO.setPosDescription(p.getPosDescription());


            JobRecruiter jobRecruiter = geekJobMapper.findJr(jrId);
            geekJobDTO.setJrId(jrId);
            geekJobDTO.setJrName(jobRecruiter.getJrName());
            geekJobDTO.setJrPosition("砌墙集团老总");
            geekJobDTO.setJrType(jobRecruiter.getJrType());
            geekJobDTO.setJrAvatar(jobRecruiter.getJrAvatar());
            geekJobDTO.setCompanyName(jobRecruiter.getCompanyName());
            geekJobDTO.setCompanyType(jobRecruiter.getCompanyType());
            geekJobDTO.setEmployeesQuantity(jobRecruiter.getEmployeesQuantity());
            if (jobRecruiter.getRunState()==1) {
                geekJobDTO.setRunState("未上市");
            }else {
                geekJobDTO.setRunState("已上市");
            }
            geekJobDTOList.add(geekJobDTO);
        }
        return geekJobDTOList;
    }

    @Override
    public JobRecruiter findById(Integer id) {
        return geekJobMapper.findJr(id);
    }

    @Override
    public List<GeekJobDTO> findSamePost(String companyName) {
        List<GeekJobDTO> geekJobDTOList = new ArrayList<>();
        List<Post> samejobs = geekJobMapper.findSameCompanyPost(companyName);
        for (Post p : samejobs) {
            int jrId=p.getJrId();
            GeekJobDTO geekJobDTO = new GeekJobDTO();
            geekJobDTO.setPosName(p.getPosName());
            geekJobDTO.setWorkPlace(p.getWorkPlace());
            geekJobDTO.setPayFloor(p.getPayFloor());
            geekJobDTO.setPayUpper(p.getPayUpper());
            geekJobDTO.setAgeDemand(p.getAgeDemand());
            geekJobDTO.setSpecialty(p.getSpecialty());

            JobRecruiter jobRecruiter = geekJobMapper.findJr(jrId);
            geekJobDTO.setCompanyName(jobRecruiter.getCompanyName());
            geekJobDTO.setCompanyType(jobRecruiter.getCompanyType());
            geekJobDTO.setEmployeesQuantity(jobRecruiter.getEmployeesQuantity());
            if (jobRecruiter.getRunState()==1) {
                geekJobDTO.setRunState("未上市");
            }else {
                geekJobDTO.setRunState("已上市");
            }
            geekJobDTOList.add(geekJobDTO);
        }
        return geekJobDTOList;
    }

}
